import {PresetStatusColorType} from "antd/es/_util/colors";
import dayjs, {Dayjs} from "dayjs";

/**
 * 日历功能
 */
export enum Feature {
    /**
     * 上个月
     */
    ToPrevMonth= 1,
    /**
     * 下个月
     */
    ToNextMonth,
    /**
     * 上一周
     */
    ToPrevWeek,
    /**
     * 下一周
     */
    ToNextWeek,
    /**
     * 上一天
     */
    ToPrevDay,
    /**
     * 下一天
     */
    ToNextDay,
    /**
     * 添加待办
     */
    AddToDo,
}

/**
 * 快捷方式转换为功能
 * @param keyCode
 * @param event
 */
export function keywordConvert(keyCode: number, event: React.KeyboardEvent<HTMLDivElement>): Feature | null{
    const {altKey, ctrlKey, shiftKey} = event;

    switch (keyCode) {
        // 左
        case 37:
            return Feature.ToPrevDay;
        // 右
        case 39:
            return Feature.ToNextDay;
        // 上
        case 38:
            return ctrlKey || altKey ? Feature.ToPrevMonth : Feature.ToPrevWeek;
        // 下
        case 40:
            return ctrlKey || altKey ? Feature.ToNextMonth : Feature.ToNextWeek;
        // 空格
        case 32:
            return Feature.AddToDo;
    }

    return null;
}

/**
 * 待办标志
 */
export enum TodoFlag {
    /**
     * 未完成
     */
    TODO = 1,
    /**
     * 完成
     */
    DONE,

    /**
     * 过期
     */
    EXPIRE,
}

/**
 * 待办程度
 */
export enum TodoLevel {
    /**
     * 紧急
     */
    URGENT,
    /**
     * 重要
     */
    IMPORTANT ,
    /**
     * 一般
     */
    NORMAL,
}

/**
 * 待办
 */
export type Todo = {
    /**
     * 时间范围
     * 如果无数值，则表示全天
     */
    time?: [Dayjs, Dayjs],
    /**
     * 标志
     */
    flag: TodoFlag,
    /**
     * 级别
     */
    level: TodoLevel,
    /**
     * 标题
     */
    title: string,
    /**
     * 内容
     */
    content?: object,
};

/**
 * 加载待办列表
 */
export function loadTodoList(day: Dayjs):Array<Todo> {

    let listData: Todo[] = []; // Specify the type of listData
    switch (day.date()) {
        case 8:
            listData = [
                { flag: TodoFlag.TODO, title: "This is warning event.1111", level: TodoLevel.NORMAL },
                { flag: TodoFlag.TODO, title: "This is warning event.2222", level: TodoLevel.NORMAL },
            ];
            break;
        case 10:
            listData = [
                { flag: TodoFlag.DONE, title: "This is very long usual event......", level: TodoLevel.NORMAL },
            ];
            break;
        case 15:
            listData = [
                { flag: TodoFlag.DONE, title: "This is warning event.1111", level: TodoLevel.NORMAL },
                { flag: TodoFlag.DONE, title: "This is warning event.2222", level: TodoLevel.URGENT },
                { flag: TodoFlag.EXPIRE, title: "This is warning event.3333", level: TodoLevel.NORMAL },
                { flag: TodoFlag.TODO, title: "This is warning event.4444", level: TodoLevel.IMPORTANT },
                { flag: TodoFlag.TODO, title: "This is warning event.5555", level: TodoLevel.NORMAL },
                { flag: TodoFlag.TODO, title: "This is warning event.6666", level: TodoLevel.NORMAL },
            ];
            break;
        default:
    }
    return listData || [];
}